package logic;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.log4j.Logger;

/**
 * Properties帮助类
 * 
 * @author 骆焕
 */
public class PropHelper {

	// 日志对象
	private final static Logger logger = Logger.getLogger(PropHelper.class);

	// 属性文件路径
	// 1. /com/linrun/config/config.properties
	// 2. config/config.properties
	final static String PROP_FILE_PATH = "config/config.properties";
	// 配置文件对象
	public static Properties prop = new Properties();

	// 静态初始块
	static {
		try {
			// 通过资源加载(/com/linrun/config/config.properties)方式:
			// InputStream is = PropHelper.class
			// .getResourceAsStream(PROP_FILE_PATH);

			// 通过缓冲流加载(config/config.properties)方式:
			InputStream is = new BufferedInputStream(new FileInputStream(
					new File(PROP_FILE_PATH)));
			prop.load(is);
		} catch (IOException e) {
			logger.error("加载数据库配置信息出错: " + e.getMessage());
		}
	}

	/**
	 * 根据key获取配置Value
	 * 
	 * @param key
	 *            键
	 * @return 值
	 */
	public static String getPropValue(String key) {
		return prop.getProperty(key);
	}

	/*
	 * public static void main(String[] args) {
	 * System.out.println(PropHelper.getPropValue("connStr")); }
	 */
}
